
{% load xadmin_forms %}
<script type="text/javascript">
<!--
    $(function() {
        $("#tabs").tabs();
        var $tabs = $('#tabs').tabs();
        $tabs.tabs('select', {{selected_tab}} ); // switch to third tab   
    });
    
    $("form").submit(function(event){
        /* event.preventDefault(); */
        var $tabs = $('#tabs').tabs();
        var selected = $tabs.tabs('option', 'selected'); 
        $("#selected_tab").val( selected )
    });

    {%if inline_collapseable %} 
	    function toggle(target, sender){
	        $(target).toggle();
	        if ( $(target).is(":hidden") ){    
	            $(sender).text("+");
	        }else{
	            $(sender).text("-");        
	        }
	        return false;
	    }
	    
	    $(document).ready(function(){        
	        $(".inside").hide();
	    })
    {% endif %}
    
    {%if inline_orderable %}
        $(function($) {
            $('div.inline-group').sortable({
                /*containment: 'parent',
                zindex: 10, */
                items: 'div.inline-related',
                handle: 'h3:first',
                update: function() {
                    $(this).find('div.inline-related').each(function(i) {
                        $(this).find('input[id$=order')
                        
                        /*
                        if ($(this).find('input[id$=order').val()) {
                            $(this).find('input[id$=order]').val(i+1);
                        }
                        */
                    });
                }
            });
            $('div.inline-related h3').css('cursor', 'move');
            /* $('div.inline-related').find('input[id$=order]').parent('div').hide(); */
        });
    {%endif%}
        
//-->
</script>
<input type="hidden" value="{{selected_tab}}" name="selected_tab" id="selected_tab">
<div id="tabs">
    <ul>
    {% for inline_admin_formset in inline_admin_formsets %}    
        <li> 
        <a href="#tabs-{{forloop.counter}}" class="{% class_if_errors inline_admin_formset.formset.errors "taberror" %}" >
        {{ inline_admin_formset.opts.verbose_name_plural|capfirst }}
        </a>
        </li>
    {% endfor %}
    </ul>

    {% for inline_admin_formset in inline_admin_formsets %}    
        <div id="tabs-{{forloop.counter}}">
            {% include inline_admin_formset.opts.template %}
        </div>
    {% endfor %}

</div>
